﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using OnlineVideos.Data;
using Common.Library;
using System.ComponentModel;
using OnlineVideos.Common;

namespace OnlineVideos.Views
{
    public partial class ShowLirics : PhoneApplicationPage
    {
        List<ShowLinkInfo> objLiricsListdes;
        public ShowLirics()
        {
            InitializeComponent();
            objLiricsListdes = new List<ShowLinkInfo>();
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            try
            {
                FlurryWP8SDK.Api.LogPageView();

            }
            catch (Exception ex)
            {

                Exceptions.SaveOrSendExceptions("Exception in OnNavigatedTo Method In ShowLirics.cs file.", ex);
            }
        }
        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            try
            {
                FlurryWP8SDK.Api.EndTimedEvent("ShowLirics Page");

            }
            catch (Exception ex)
            {

                Exceptions.SaveOrSendExceptions("Exception in OnNavigatedFrom Method In ShowLirics.cs file.", ex);
            }
        }
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                FlurryWP8SDK.Api.LogEvent("ShowLirics Page", true);
                GetPageDataInBackground();
            }
            catch (Exception ex)
            {
                
               Exceptions.SaveOrSendExceptions("Exception in PhoneApplicationPage_Loaded Method In ShowLirics.cs file.", ex);
            }
        }

        private void GetPageDataInBackground()
        {
            BackgroundHelper bwHelper = new BackgroundHelper();

            bwHelper.AddBackgroundTask(
                                        (object s, DoWorkEventArgs a) =>
                                        {
                                            a.Result = OnlineShow.GetLyrics(AppSettings.ShowID, AppSettings.LiricsLink/*, false*/);
                                        },
                                        (object s, RunWorkerCompletedEventArgs a) =>
                                        {
                                            objLiricsListdes = (List<ShowLinkInfo>)a.Result;
                                            if (objLiricsListdes.Count > 0)
                                            {
                                                lbxLyricsList.ItemsSource = objLiricsListdes;
                                                tblkFavNoLyricsDescription.Visibility = Visibility.Collapsed;
                                            }
                                            else
                                            {
                                                tblkFavNoLyricsDescription.Visibility = Visibility.Visible;
                                            }
                                        }
                                      );

            bwHelper.RunBackgroundWorkers();
        }
    }
}